import {AxiosPromise, Option} from "@/types/common";
import {get, post, put} from "@/utils/request";

/**
 * 根据 ID 测试连接
 * @param id 数据库信息ID
 */
export const useDataSourceTestApi = (id: Number): AxiosPromise<boolean> => {
	return get('/generator/v1/datasource/test/' + id)
}

/**
 * 根据 ID 查询数据源信息
 * @param id
 */
export const useDataSourceApi = (id: Number) => {
	return get('/generator/v1/datasource/' + id)
}

/**
 * 数据源选项列表
 */
export const useDataSourceOptionListApi = (): AxiosPromise<Option[]> => {
	return get('/generator/v1/datasource/options')
}

/**
 * 新增或修改
 * @param dataForm 数据库表单
 */
export const useDataSourceSubmitApi = (dataForm: any): AxiosPromise<boolean> => {
	if (dataForm.id) {
		return put('/generator/v1/datasource', dataForm)
	} else {
		return post('/generator/v1/datasource', dataForm)
	}
}

/**
 * 获取数据源表列表
 * @param id 数据源 ID
 */
export const useDataSourceTableListApi = (id: string) => {
	return get('/generator/v1/datasource/table/list/' + id)
}
